package miiteen.hb.zwxx.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import miiteen.core.result.ResultMessage;
import miiteen.core.result.ResultMessageTool;
import miiteen.customsportal.basic.service.HistoryViewService;
import miiteen.data.beans.PageBounds;
import miiteen.hb.zwxx.beans.Zwxx;
import miiteen.hb.zwxx.service.ZwxxService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Api("政务信息")
@RequestMapping("/hb/zwxx")
@RestController
@CrossOrigin
public class ZwxxController {

    @Autowired
    private ZwxxService zwxxService;
    @Autowired
    private HistoryViewService historyViewService;

    @ApiOperation("兰关动态")
    @GetMapping("/lgdt")
    public ResultMessage<List<Zwxx>> lgdt(@RequestParam int pageSize, @RequestParam int pageNum, String subject) {
        //获取查询条件
        PageBounds pageBounds = new PageBounds();
        pageBounds.setPageNum(pageNum);
        pageBounds.setPageSize(pageSize);
        Map<String, Object> map = new HashMap<>();
        map.put("mediaTypeId", "3e1afcd9-f106-492e-b3b5-13f1a2d4df36");
        map.put("orderby", "COMPLETE_DATE desc");
        map.put("releaseFlag", 1);
        if (StringUtils.isNotBlank(subject)) {
            map.put("subject", "%" + subject + "%");
        }
        //查询数据
        List<Zwxx> list = zwxxService.findListByMap(map, pageBounds);
        historyViewService.fillVisitCount(list);
        if (list != null && list.size() > 0) {
            return ResultMessageTool.Success(String.valueOf(pageBounds.getTotal()), list);
        } else {
            return ResultMessageTool.Success("0", new ArrayList<>());
        }
    }

    @ApiOperation("情况通报")
    @GetMapping("/qktb")
    public ResultMessage<List<Zwxx>> qktb(@RequestParam int pageSize, @RequestParam int pageNum, String subject) {
        //获取查询条件
        PageBounds pageBounds = new PageBounds();
        pageBounds.setPageNum(pageNum);
        pageBounds.setPageSize(pageSize);
        Map<String, Object> map = new HashMap<>();
        map.put("mediaTypeId", "2a6c22fb-6bd4-4f6b-912d-9bc1a172485c");
        map.put("orderby", "COMPLETE_DATE desc");
        map.put("releaseFlag", 1);
        if (StringUtils.isNotBlank(subject)) {
            map.put("subject", "%" + subject + "%");
        }
        //查询数据
        List<Zwxx> list = zwxxService.findListByMap(map, pageBounds);
        historyViewService.fillVisitCount(list);
        if (list != null && list.size() > 0) {
            return ResultMessageTool.Success(String.valueOf(pageBounds.getTotal()), list);
        } else {
            return ResultMessageTool.Success("0", new ArrayList<>());
        }
    }

    @ApiOperation("工作简报")
    @GetMapping("/gzjb")
    public ResultMessage<List<Zwxx>> gzjb(@RequestParam int pageSize, @RequestParam int pageNum, String subject) {
        //获取查询条件
        PageBounds pageBounds = new PageBounds();
        pageBounds.setPageNum(pageNum);
        pageBounds.setPageSize(pageSize);
        Map<String, Object> map = new HashMap<>();
        map.put("mediaTypeId", "1c0a5dc6-a0c0-4983-8239-303f615e6627");
        map.put("orderby", "COMPLETE_DATE desc");
        map.put("releaseFlag", 1);
        if (StringUtils.isNotBlank(subject)) {
            map.put("subject", "%" + subject + "%");
        }
        //查询数据
        List<Zwxx> list = zwxxService.findListByMap(map, pageBounds);
        historyViewService.fillVisitCount(list);
        if (list != null && list.size() > 0) {
            return ResultMessageTool.Success(String.valueOf(pageBounds.getTotal()), list);
        } else {
            return ResultMessageTool.Success("0", new ArrayList<>());
        }
    }

    @ApiOperation("综合参阅")
    @GetMapping("/zhcy")
    public ResultMessage<List<Zwxx>> zhcy(@RequestParam int pageSize, @RequestParam int pageNum, String subject) {
        //获取查询条件
        PageBounds pageBounds = new PageBounds();
        pageBounds.setPageNum(pageNum);
        pageBounds.setPageSize(pageSize);
        Map<String, Object> map = new HashMap<>();
        map.put("mediaTypeId", "f7c6f566-7775-4a34-a985-ad35f4d5afdc");
        map.put("orderby", "COMPLETE_DATE desc");
        map.put("releaseFlag", 1);
        if (StringUtils.isNotBlank(subject)) {
            map.put("subject", "%" + subject + "%");
        }
        //查询数据
        List<Zwxx> list = zwxxService.findListByMap(map, pageBounds);
        historyViewService.fillVisitCount(list);
        if (list != null && list.size() > 0) {
            return ResultMessageTool.Success(String.valueOf(pageBounds.getTotal()), list);
        } else {
            return ResultMessageTool.Success("0", new ArrayList<>());
        }
    }
}
